DM 'CLEAR LOG; CLEAR OUTPUT;';

libname temp 'C:\Users\SAMIC\Documents\Version_FINALE\Envoi_Final_REStat\Envoi_pgm\Verif_data';

options linesize = 100;
options pagesize = 72;


/** TABLE 1 **/

/** computation of statistics for the initial business survey database**/
data temp.base_init_stat; set temp.ACEMO_EC;
price_change =(evprpf ne 3);
price_increase =(evprpf < 3);
price_decrease =(evprpf > 3);

iip_change =(evprmp ne 3);
iip_increase =(evprmp < 3);
iip_decrease =(evprmp > 3);

prod_change =(evpro ne 3);
prod_increase =(evpro < 3);
prod_decrease =(evpro > 3);

order_change = (evcom ne 3);
order_increase = (evcom <3);
order_decrease = (evcom >3);

inventory_change = (evstpf ne 3);
inventory_increase = (evstpf <3);
inventory_decrease = (evstpf >3);
run;

proc sort data = temp.base_init_stat; by naf_mc; run;
data temp.base_init_stat; merge temp.base_init_stat(in=in1) temp.table_passage_nomenclatures; by naf_mc; 
if in1;
run;

title ' Table 1 - statistics for the initial business survey database';
proc freq data = temp.base_init_stat;
tables price_change price_increase price_decrease;
tables iip_change iip_increase iip_decrease;
tables prod_change prod_increase prod_decrease;
tables order_change order_increase order_decrease;
tables inventory_change inventory_increase inventory_decrease;
run;


/** computation of wage changes from the initial quarterly ACEMO survey database**/
data acemo_init; set temp.base_entreprises_reduite_def; 
where isalmtot2 ne .;
wage_change= (isalmtot2 ne 0  );
wage_increase= (isalmtot2 > 0 );
wage_decrease= (isalmtot2 < 0 );
run;

title 'Table 1 - quarterly wage changes from the ACEMO survey';
proc freq data=acemo_init;
tables wage_change wage_increase wage_decrease ; 
run;


/** computation of statistics for the econometric database **/
data temp.base_stat_des; set temp.stata_base_q3_asym_chocs;

price_change =(evprpf ne 0);
price_increase =(evprpf > 0);
price_decrease =(evprpf < 0);

iip_change =(evprmp ne 0);
iip_increase =(evprmp > 0);
iip_decrease =(evprmp < 0);

prod_change =(evpro ne 0);
prod_increase =(evpro > 0);
prod_decrease =(evpro < 0);

wage_change= (isalmtot2 ne 0);
wage_increase= (isalmtot2 > 0);
wage_decrease= (isalmtot2 < 0);

order_change = (evcom ne 0);

inventory_change = (evstpf ne 0);

cost_change = (iip_change+wage_change >0); 
envir_change = (iip_change+wage_change+prod_change >0); 

l1_iip_change =(l1_evprmp ne 0);
l1_prod_change =(l1_evpro ne 0);
l1_wage_change= (l1_isalmtot2 ne 0);
l1_envir_change = (l1_iip_change+l1_wage_change+l1_prod_change >0); 

trim = (mois in (1,2,3)) + 2*(mois in (4,5,6)) + 3*(mois in (7,8,9)) + 4*(mois in (10,11,12));
run;


title 'Table 1 - frequency of changes from the econometric database';
proc freq data = temp.base_stat_des;
tables evprpf ;
tables evprmp ;
tables isalmtot2;
tables evpro ;
tables evcom ;
tables evstpf ;
tables txipp2 ;
run;
 
title 'Table 1 - frequency of changes that can be seen as permanent ones';
proc freq data = temp.base_stat_des;
tables evprpf_perm3  ;
tables iip_perm3  ;
tables prod_perm3 ;
tables ord_perm3  ;
tables inv_perm3  ;
tables ipp_perm3  ;

tables evprpf_i3_up; 
tables evprpf_p3_up;
tables evprpf_i3_down;
tables evprpf_p3_down; 

tables evprmp_i3_up; 
tables evprmp_p3_up;
tables evprmp_i3_down;
tables evprmp_p3_down; 

tables evpro_i3_up; 
tables evpro_p3_up;
tables evpro_i3_down;
tables evpro_p3_down; 

tables evcom_i3_up; 
tables evcom_p3_up;
tables evcom_i3_down;
tables evcom_p3_down; 

tables evstpf_i3_up; 
tables evstpf_p3_up;
tables evstpf_i3_down;
tables evstpf_p3_down; 

tables txipp2_i3_up; 
tables txipp2_p3_up;
tables txipp2_i3_down;
tables txipp2_p3_down; 

run;
 
/** computation of the Konieczny-Fisher synchronisation index (quarterly frequency)**/
proc sort data=temp.base_stat_des; by ident_stata annee trim; run;

proc means noprint data=temp.base_stat_des; by ident_stata annee trim;
var price_change iip_change wage_change prod_change  order_change inventory_change;
output out = synchro_b sum = d_p d_iip d_w d_prod d_ord d_inv;
id naf_gc;
run;

data synchro_b; set synchro_b;
price_change = (d_p>0);
iip_change = (d_iip >0);
wage_change= (d_w >0);
prod_change = (d_prod >0);
order_change = (d_ord >0);
inventory_change = (d_inv >0);
run;

proc sort data=synchro_b; by naf_gc annee trim; run;

proc means noprint data=synchro_b; by naf_gc annee trim;
var price_change iip_change wage_change prod_change  order_change inventory_change;
output out = synchro_c mean = f_p f_iip f_w f_prod f_ord f_inv;
run;

proc means noprint data = synchro_c; by naf_gc;
where naf_gc ne 'DF';
var f_p f_iip f_w f_prod f_ord f_inv;
output out = synchro4 mean = mf_p mf_iip mf_w mf_prod mf_ord mf_inv 
                    std = sf_p sf_iip sf_w sf_prod sf_ord sf_inv;
run;

data synchro4; set synchro4;
where naf_gc ne 'DF';
ifk_p = sf_p/((mf_p*(1-mf_p))**0.5);
ifk_iip = sf_iip/((mf_iip*(1-mf_iip))**0.5);
ifk_w = sf_w/((mf_w*(1-mf_w))**0.5);
ifk_prod = sf_prod/((mf_prod*(1-mf_prod))**0.5);
ifk_ord = sf_ord/((mf_ord*(1-mf_ord))**0.5);
ifk_inv = sf_inv/((mf_inv*(1-mf_inv))**0.5);
run;

title 'Table 1 - synchronization index ';
proc means data = synchro4; 
var ifk_p ifk_iip ifk_w ifk_prod ifk_ord ifk_inv ;
run;

 
/** TABLE 2 **/

title 'Table 2 - column 1';
proc freq data=temp.base_stat_des; 
tables price_change*envir_change;
run;

title 'Table 2 - column 1(cont.d)';
proc freq data=temp.base_stat_des; 
tables cost_change*prod_change;
run;

title 'Table 2 - column 1(cont.d)';
proc freq data=temp.base_stat_des; 
tables wage_change*iip_change;
run;

title 'Table 2 - column 2(cont.d)';
proc freq data=temp.base_stat_des; 
where cost_change = 1 and prod_change = 1;
tables price_change;
run;

title 'Table 2 - column 2(cont.d)';
proc freq data=temp.base_stat_des; 
where cost_change = 1 and prod_change = 0;
tables price_change;
run;

title 'Table 2 - column 2(cont.d)';
proc freq data=temp.base_stat_des; 
where cost_change = 0 and prod_change = 1;
tables price_change;
run;

title 'Table 2 - column 2(cont.d)';
proc freq data=temp.base_stat_des; 
where cost_change = 0 and prod_change = 0;
tables price_change;
run;

title 'Table 2 - column 2   wage_change = 1 and iip_change = 1';
proc freq data=temp.base_stat_des; 
where wage_change = 1 and iip_change = 1;
tables price_change;
run;

title 'Table 2 - column 2   wage_change = 0 and iip_change = 1';
proc freq data=temp.base_stat_des; 
where wage_change = 0 and iip_change = 1;
tables price_change;
run;

title 'Table 2 - column 2 wage_change = 1 and iip_change = 0';
proc freq data=temp.base_stat_des; 
where wage_change = 1 and iip_change = 0;
tables price_change;
run;

title 'Table 2 - column 2 wage_change = 0 and iip_change = 0';
proc freq data=temp.base_stat_des; 
where wage_change = 0 and iip_change = 0;
tables price_change;
run;


/** TABLE 3 **/
title 'Table 3';
proc freq data=temp.base_stat_des; 
tables evprmp*isalmtot2;
run;

title 'Table 3 - columns 2-3 where wage_decrease = 1 and iip_decrease = 1';
proc freq data=temp.base_stat_des; 
where wage_decrease = 1 and iip_decrease = 1;
tables evprpf;
run;

title 'Table 3 - columns 2-3  where wage_increase = 1 and iip_increase = 1';
proc freq data=temp.base_stat_des; 
where wage_increase = 1 and iip_increase = 1;
tables evprpf;
run;

title 'Table 3 - columns 2-3 where wage_decrease ne 1 and iip_decrease = 1';
proc freq data=temp.base_stat_des; 
where wage_decrease ne 1 and iip_decrease = 1;
tables evprpf;
run;

title 'Table 3 - columns 2-3  where wage_increase ne 1 and iip_increase = 1';
proc freq data=temp.base_stat_des; 
where wage_increase ne 1 and iip_increase = 1;
tables evprpf;
run;

title 'Table 3 - columns 2-3  where wage_increase ne 1 and iip_change = 0';
proc freq data=temp.base_stat_des; 
where wage_increase ne 1 and iip_change = 0;
tables evprpf;
run;

title 'Table 3 - columns 2-3   where wage_increase = 1 and iip_change = 0';
proc freq data=temp.base_stat_des; 
where wage_increase = 1 and iip_change = 0;
tables evprpf;
run;


/** Table S1 **/
title 'Table S1';
proc freq data = temp.base_init_stat(where = (naf_gc ne 'DF' & annee = 2005 & mois = 1)); 
tables naf_gc;
run;

proc freq data=temp.base_stat_des; 
where annee = 2005 and mois = 1;
tables naf_gc;
run;

/* Number of firms in the sample */
proc sort data = temp.base_stat_des; by siren; run;

data nb_firms; set temp.base_stat_des; by siren;
if first.siren;
run;

/* Number of products in the sample */
proc sort data = temp.base_stat_des; by siren etabl ape; run;

data nb_products; set temp.base_stat_des; by siren etabl ape;
if first.siren or first.etabl or first.ape;
run;
